home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 326-350 / disk_337 / cmanual / miscellaneous.lzh / Miscellaneous / Example2.c < prev    next >
C/C++ Source or Header  |  1990-02-08  |  2KB  |  75 lines

  1. /* Example2                                                              */
  2. /* This example shows how to allocate and deallocate memory with help of */
  3. /* the functions AllocRemember(), and FreeRemember().                    */
  4.  
  5.  
  6. #include <intuition/intuition.h>
  7. #include <exec/memory.h>
  8.  
  9.  
  10. struct IntuitionBase *IntuitionBase;
  11.  
  12.  
  13. main()
  14. {
  15.   /* Declare and initialize a pointer to the first Remember structure: */
  16.   struct Remember *remember = NULL;
  17.   
  18.   /* Declare three memory pointers: */
  19.   CPTR memory1, memory2, memory3;
  20.  
  21.  
  22.  
  23.   /* Open the Intuition Library: */
  24.   IntuitionBase = (struct IntuitionBase *)
  25.     OpenLibrary( "intuition.library", 0 );
  26.   
  27.   if( IntuitionBase == NULL )
  28.     exit(); /* Could NOT open the Intuition Library! */
  29.  
  30.  
  31.  
  32.   /* Allocate 350 bytes of Chip memory, which is cleared: */
  33.   memory1 = AllocRemember( &remember, 350, MEMF_CHIP|MEMF_CLEAR );
  34.  
  35.   if( memory1 == NULL )
  36.   {
  37.     CloseLibrary( IntuitionBase );
  38.     exit();
  39.   }
  40.  
  41.  
  42.   /* Allocate 900 bytes of memory (any type, Fast if possible): */
  43.   memory2 = AllocRemember( &remember, 900, MEMF_PUBLIC );
  44.  
  45.   if( memory2 == NULL )
  46.   {
  47.     FreeRemember( &remember, TRUE );
  48.     CloseLibrary( IntuitionBase );
  49.     exit();
  50.   }
  51.  
  52.  
  53.   /* Allocate 100 bytes of Chip memory: *
  54.   memory3 = AllocRemember( &remember, 100, MEMF_CHIP );
  55.  
  56.   if( memory3 == NULL )
  57.   {
  58.     FreeRemember( &remember, TRUE );
  59.     CloseLibrary( IntuitionBase );
  60.     exit();
  61.   }
  62.  
  63.  
  64.  
  65.   /* Do whatever you want to do with the memory. */
  66.  
  67.  
  68.  
  69.   /* Deallocate all memory with one single call: */
  70.   FreeRemember( &remember, TRUE );
  71.  
  72.   /* Close the Intuition Library: */
  73.   CloseLibrary( IntuitionBase );
  74. }
  75.